<?php 
class Room_model extends CI_Model
{
	//get all data of room
	public function get_all_room()
	{
		$sql = "Select * from room order by roomname;";
		$query = $this->db->query($sql);
		
		if($query->num_rows() > 0)
		{
			foreach ($query->result() as $row) {
				$data[] = $row;
			}
		}
		return $data;
	}
	
	public function get_room_by_type($type)
	{
		$sql = "Select * from room where roomtype=$type order by roomname;";
		$query = $this->db->query($sql);
		
		if($query->num_rows() > 0)
		{
			foreach ($query->result() as $row)
			{
				$data[] = $row;
			}
			return $data;
		}
	}
	
	//add new room
	public function addnewroom($roomname, $roomtype, $build, $roompic, $roommax, $comcount, $sw, $hw, $roomstat)
	{
		$array = array(
			'roomname' => $roomname,
			'roomtype' => $roomtype,
			'build' => $build,
			'roompic' => $roompic,
			'roommax' => $roommax,
			'comcount' => $comcount,
			'sw' => $sw,
			'hw' => $hw,
			'roomstat' => $roomstat
		);
		
		$query = $this->db->insert('room', $array);
		
		if($query == true)
		{
			return true;
		}
		else {
			return false;
		}
		
	}
	
	//delete room
	public function deleteroom($roomname)
	{
		$sql = "Delete from room where roomname='$roomname';";
		$del = $query = $this->db->query($sql);
		
		if($del == true)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	
	//update room
	public function updateroom($roomname, $roomtype, $build, $roompic, $roommax, $comcount, $sw, $hw, $roomstat)
	{
		$sql = "Update room set roomtype=$roomtype, build='$build', roompic='$roompic', roommax=$roommax, comcount=$comcount, sw='$sw', hw='$hw' roomstat=$roomstat where roomname='$roomname';";
		$query = $this->db->query($sql);
		
		if($query == true)
		{
			return true;
		}
		else{
			return false;
		}
	}
}